$(function () {
    $("body").on('click','#save-note-btn',function () {
        saveCourseNote();
    }).on('keyup','#course-note-context',function () {
        $("#note-error-box").parent().parent().addClass('hide');
        $("#note-error-box").html('');
    });

    /**
     * 保存课程笔记
     */
    function saveCourseNote() {
        //笔记内容
        var note = $("#course-note-context").val();
        var playId = $("#playId").val();
        var buyCourseId = $("#buyCourseId").val();
        var courseId = $("#courseId").val();
        var progress = studyTime;//播放进度，文章则为0
        if(playId==0||playId==""||playId==null){
            icModale(0,'','抱歉没有在学习的章节无法记录笔记');
        }
        if(note==""||note==null){
            icModale(0,'','请填写记录的内容');
        }
        var params = {
            'buyCourseId':buyCourseId,
            'courseId':courseId,
            'catalogId':playId,
            'progress':progress,
            'note':note
        };
        params = JSON.stringify(params);
        $.ajax({
            url:baseloaction +'/web/uc/course/note/saveCourseNote',
            type:'post',
            dataType:'json',
            data:params,
            contentType: 'application/json;charset=utf-8',
            success:function (result) {
                if(result.success==true){
                    $("#course-note-context").val('');
                    listCourseNote(1);
                }else{
                    $("#note-error-box").parent().parent().removeClass('hide');
                    $("#note-error-box").html(result.message);
                }
            },
            error:function (error) {
                $("#note-error-box").parent().parent().removeClass('hide');
                $("#note-error-box").html('系统错误，课程笔记保存失败');
            }
        });
    }
});

/**
 * 加载笔记
 * @param pageNo 第N页数据
 */
function listCourseNote(pageNo) {
    var courseId = $('#courseId').val();
    var catalogId = $('#playId').val();
    var params = {
        courseId: courseId,
        catalogId: catalogId
    };
    params = JSON.stringify(params);
    getPageAjaxData({
        url: baseloaction + '/web/uc/course/note/ajaxCourseNoteList',//请求URL
        contextId:'course-note-list-box',//响应内容页面设置内容ID
        params:params,//请求参数
        pageNo:pageNo,//页码
        pageCall:listCourseNote, //分页回调加载数据(点击上下页时调用,该方法也在加载页面完成时调用)
        callback:function () {//数据加载完成回调
            /*$('.sidebar-collapse').slimScroll({
                height: '100%',
                railOpacity: 0.9,
                alwaysVisible: false
            });*/
        }
    });
}
